package com.ck.client.service.async;

import com.ck.client.service.DeviceHeartBeatService;
import com.ck.client.service.DeviceInfoService;
import com.ck.common.model.bo.DeviceReportBO;
import com.ck.core.constant.BusinessConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
* @Description: 异步执行方法
* @Author: hf
* @Date:    2019/5/13 10:42
* @Version: 1.0
*/
@Component
public class AsyncService {
	private static Logger logger = LoggerFactory.getLogger(AsyncService.class);

	@Autowired
	private DeviceInfoService deviceInfoService;
	@Autowired
	private DeviceHeartBeatService deviceHeartBeatService;

	/**
	 * 异步更新设备上报信息
	 * @param deviceReport
	 */
	@Async
	public void deviceReport( DeviceReportBO deviceReport ){
		deviceReport.setLastReportTime(System.currentTimeMillis());
		deviceReport.setDeviceStatus(BusinessConstant.DEVICE_INFO_STATUS_ON_LINE);

		// 更新终端基础信息表
		deviceInfoService.report(deviceReport);

		// 设备上线处理
		deviceHeartBeatService.online( deviceReport.getDeviceCode(),deviceReport.getLastReportTime() );

	}

}
